<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>组件基础</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    {{msg}}
    <my-com1 :obj="{name:'zhangsan'}" title="hello" :msg-attr="msg" :flag="10"></my-com1>
  </div>
  <script>
    // 定义组件
    let component1 = {
      props: ['title', 'msgAttr', 'flag', 'obj'],
      data() {
        return {
          comMsg: '组件数据'
        }
      },
      template: `
        <div>
          <p>我是vue的组件</p>
          <h1>{{comMsg}}</h1>
          <button @click="clickHandler">修改数据</button>
          <span>父组件传递过来的数据：{{title}}---{{msgAttr}}</span>
          布尔：{{flag}}<br>
          对象：{{obj}}

        </div>
      `,
      methods: {
        clickHandler() {
          this.comMsg = '新的组件数据'
        }
      },
      created() {
        console.log(this.flag);
      }
    }
    // 组件注册
    // 全局注册
    // Vue.component('my-com2', component2)
    let vm = new Vue({
      el: '#app',
      data: {
        msg: 'hello vue component'
      },
      methods: {

      },
      components: {
        'my-com1': component1
      }
    })
  </script>
</body>

</html>